<template>
  <div class="house">
    <div class="house_header" v-for="v in houseList" :key="v.id">
      <h3>{{ v.title }}</h3>
      <ul>
        <li
          :class="activeIndex === index ? 'active' : ''"
          v-for="(item, index) in v.children"
          :key="index"
          @click="activeIndex = index"
        >
          {{ item }}
        </li>
      </ul>
    </div>
    <div class="house_header" v-for="v in houseList2" :key="v.id">
      <h3>{{ v.title }}</h3>
      <ul>
        <li
          :class="activeIndex2 === index ? 'active' : ''"
          v-for="(item, index) in v.children"
          :key="index"
          @click="getHouse(item, index)"
        >
          {{ item }}
        </li>
      </ul>
    </div>
    <button @click="submit(e)">确定</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: 0,
      activeIndex2: 0,
      houseList: [
        {
          title: "买房选型",
          children: ["不限", "新房", "二手房"],
        },
      ],
      houseList2: [
        {
          title: "户型",
          children: ["不限", "1室", "2室", "3室", "4室"],
        },
      ],
    };
  },
  methods: {
    submit(e) {
      this.$emit("submit", "");
    },
    getHouse(item, index) {
      this.activeIndex2 = index;
      // console.log(item);
      this.$emit("getHouse", item);
    },
  },
  created() {},
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.house {
  width: 98%;
  position: absolute;
  top: 210px;
  left: 0;
  background: #fff;
}

.house_header {
  width: 100%;
  height: auto;
  margin: 20px;
  text-align: center;
}
.house_header h3 {
  line-height: 30px;
}

.house_header ul {
  width: 100%;
  height: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
}
.house > button {
  width: 100%;
  height: 50px;
  border: 0;
  outline: none;
  background: tomato;
  margin-top: 160px;
  color: #fff;
}
.house_header ul .active {
  background: orange;
  color: #fff;
}
.house_header ul li {
  padding: 5px 15px;
  background: #eee;
  color: #878787;
  margin: 5px;
}
</style>